<template>
  <div class="dashboard-container">
    <component :is="currentRole" />
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import adminDashboard from './admin'
import editorDashboard from './editor'

export default {
  name: 'Dashboard',
  components: { adminDashboard, editorDashboard },
  data() {
    return {
      currentRole: 'adminDashboard'
    }
  },
  computed: {
    ...mapGetters([
      'roles'
    ])
  },
  /*
  * {
  data() {
    return {}
  },
  created() {
    if (!this.roles.includes('admin')) {
      this.currentRole = 'editorDashboard'
    }
    this.getCookie('tenantId')
  },
  methods: {
    getCookie(name) {
      var cookieStr = document.cookie
      var cookies = cookieStr.split('; ')
      for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i].split('=')
        if (cookie[0] === name) {
          console.log(cookie[1])
          alert(cookie[1])
        }
      }
    }
  }
}
*/
  created() {
    if (!this.roles.includes('admin')) {
      this.currentRole = 'editorDashboard'
    }
    this.getCookie('tenantid')
  },
  methods: {
    getCookie(name) {
      var cookieStr = document.cookie
      var cookies = cookieStr.split('; ')
      for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i].split('=')
        if (cookie[0] === name) {
          console.log(cookie[1])
          // alert(cookie[1])
        }
      }
    }
  }
}
</script>
